package cpool;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 连接类
 */
public class PoolConnection {
    /**
     * 数据库连接
     */
    private Connection conn=null;
    /**
     * 该连接是否可用
     */
    private  boolean isUse=false;

    public Connection getConn() {
        return conn;
    }

    public void setConn(Connection conn) {
        this.conn = conn;
    }

    public boolean isUse() {
        return isUse;
    }

    public void setUse(boolean use) {
        isUse = use;
    }

    public PoolConnection(Connection conn, boolean isUse) {
        this.conn = conn;
        this.isUse = isUse;
    }

    /**
     * 查询实现
     */
    public ResultSet queryBySql(String sql){
        Statement sm=null;
        ResultSet rs=null;
        try {
            sm=conn.createStatement();
            rs=sm.executeQuery(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return rs;
    }
    /**
     * 将该连接置为可用状态
     */
    public void close(){
        this.isUse=false;
    }
}
